<?php

namespace MyApp\Controllers\Admin;

use MyApp\Models\Admin;
use Phalcon\Mvc\Controller;

class LoginController extends Controller
{

    public function indexAction()
    {
        return $this->view->render('admin', 'login');
    }

    public function loginAction()
    {
        $data = $this->request->get();
        $username = $data['username'];
        $password = $data['password'];

        $admin = Admin::findFirst([
            'conditions' => "username = ?0",
            'bind' => [
                $username
            ]
        ]);
        if ($admin && $admin->password == password($password)) {
            session('id', $admin->id);
            session('password', $password);
            return success();
        }
        return error('密码错误！！');
    }

}

